function check{
$device = Get-WmiObject Win32_PNPEntity
$erro = $device |select Name,Status | Export-Csv -Encoding UTF8 -Path "$env:USERPROFILE\device.csv"
$name = Get-Content "$env:USERPROFILE\device.csv" | where{$_ -match "Error"}
if($name -match "Error"){
    Write-Output $name}}

check{}
